// IMPORTANT: Read the license included with this code archive.

namespace Hosting
{
    using System;
    using System.Collections;
    using System.Drawing;
    using System.Windows.Forms;
    using System.Windows.Forms.Design;

    public class UIService : IUIService
    {
        private readonly Form mainForm;

        private readonly Hashtable styles;

        public UIService(Form mainForm)
        {
            this.mainForm = mainForm;

            this.styles = new Hashtable();
            this.styles.Add("DialogFont", new Font("Tahoma", 8.25F, FontStyle.Regular));
            this.styles.Add("HighlightColor", Color.FromArgb(255, 251, 233));
        }

        public bool CanShowComponentEditor(object component)
        {
            return false;
        }

        public System.Windows.Forms.IWin32Window GetDialogOwnerWindow()
        {
            return this.mainForm;
        }

        public void SetUIDirty()
        {
            // Do nothing
        }

        public bool ShowComponentEditor(object component, System.Windows.Forms.IWin32Window parent)
        {
            return false;
        }

        public System.Windows.Forms.DialogResult ShowDialog(System.Windows.Forms.Form form)
        {
            return form.ShowDialog(this.mainForm);
        }

        public void ShowError(System.Exception ex, string message)
        {
            MessageBox.Show(this.mainForm, "Piped error: " + message + Environment.NewLine + Environment.NewLine + ex);
        }

        public void ShowError(System.Exception ex)
        {
            MessageBox.Show(this.mainForm, "Piped error: " + ex);
        }

        public void ShowError(string message)
        {
            MessageBox.Show(this.mainForm, "Piped error: " + message);
        }

        public System.Windows.Forms.DialogResult ShowMessage(
            string message, string caption, System.Windows.Forms.MessageBoxButtons buttons)
        {
            return MessageBox.Show(this.mainForm, message, caption, buttons, MessageBoxIcon.Information);
        }

        public void ShowMessage(string message, string caption)
        {
            MessageBox.Show(this.mainForm, message, caption);
        }

        public void ShowMessage(string message)
        {
            MessageBox.Show(this.mainForm, message);
        }

        public bool ShowToolWindow(System.Guid toolWindow)
        {
            return false;
        }

        public System.Collections.IDictionary Styles
        {
            get
            {
                return this.styles;
            }
        }
    }
}